﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<%
	String path = request.getContextPath();
%>
<div class="cl pd-5 bg-1 bk-gray mt-20">
    <ul>
        <li style="float: left;margin-left: 5px;"><span>审核状态：</span></li>
        <li style="float: left;margin-left: 5px;"><a onclick="initData(0)" class="label label-success radius" >审核通过</a></li>
        <li style="float: left;margin-left: 5px;"><a onclick="initData(1)" class="label label-success radius">待审核</a></li>
        <li style="float: left;margin-left: 5px;"><a onclick="initData(null)" class="label label-success radius">全部</a></li>
        <li><span class="r">共有数据：<strong>${fn:length(allGarbage)}</strong> 条</span></li>
    </ul>
</div>
    <div>
     <table class="table table-border table-bordered table-bg table-hover table-sort">
         <thead>
         <tr class="text-c">
             <th width="40">ID</th>
             <th width="60">缩略图</th>
             <th width="70">垃圾名称</th>
             <th width="70">垃圾类型</th>
             <th width="50">垃圾材质</th>
             <th>描述</th>
             <th width="70">处理方式</th>
             <th width="100">发布者</th>
             <th width="60">审核状态</th>
             <th width="100">操作</th>
         </tr>
         </thead>
         <tbody>
         <c:forEach items="${requestScope.allGarbage}" var="garbage">
             <tr id="single" data-id="${garbage.id}" class="text-c va-m">
                 <td>${garbage.id}</td>
                 <td><a onClick="product_show('${garbage.name}','<%=path%>/static/images/${garbage.picture}','10001','300','300')" href="javascript:;"><img width="60" class="product-thumb" src="<%=path%>/static/images/${garbage.picture}"></a></td>
                 <td><span class="price">${garbage.name}</span></td>
                 <td><span class="price">${garbage.garbageType.title}</span></td>
                 <td><span class="price">${garbage.texture.title}</span></td>
                 <td><a class="price" href="javascript:void(0);" onclick="Detail_show('文章详情','<%=path%>/backstage/garbage/information?id=${garbage.id}','10001','600','400')">查看详情</a></td>
                 <td><a onclick="Detail_show('处理方式','<%=path%>/backstage/garbage/solution?id=${garbage.id}','10001','600','400')" class="price">${garbage.solutionCount}</a></td>
                 <td><a class="price" onclick="Detail_show('发布垃圾用户信息','<%=path%>/backstage/garbage/userinfo?id=${garbage.userinfo.id}','10001','400','500')">${garbage.userinfo.nickname}</a></td>
                 <c:if test="${garbage.checked=='0'}">
                     <td class="td-status"><span class="label label-success radius">已审核</span></td>
                     <td garbageId="${garbage.id}" class="td-manage">
                         <a style="text-decoration:none" onClick="product_start(this,'10001')" href="javascript:;" title="更改为未审核"><i class="Hui-iconfont">&#xe6de;</i></a>
                         <a style="text-decoration:none" class="ml-5"  href="<%=path%>/backstage/garbage/edit?id=${garbage.id}" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>
                         <a style="text-decoration:none" class="ml-5${garbage.id}" data-id="${garbage.id}" onClick="product_del(this,'10001')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>
                     </td>
                 </c:if>
                 <c:if test="${garbage.checked=='1'}">
                     <td class="td-status"><span class="label label-defaunt radius">未审核</span></td>
                     <td garbageId="${garbage.id}" class="td-manage">
                         <a style="text-decoration:none" onClick="product_stop(this,'10001')" href="javascript:;" title="通过审核"><i class="Hui-iconfont">&#xe603;</i></a>
                         <a style="text-decoration:none" class="ml-5"  href="<%=path%>/backstage/garbage/edit?id=${garbage.id}" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>
                         <a style="text-decoration:none" class="ml-5${garbage.id}" data-id="${garbage.id}" onClick="product_del(this,'10001')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>
                     </td>
                 </c:if>
             </tr>
         </c:forEach>
         </tbody>
     </table>
 </div>
<script type="text/javascript">
var setting = {
	view: {
		dblClickExpand: false,
		showLine: false,
		selectedMulti: false
	},
	data: {
		simpleData: {
			enable:true,
			idKey: "id",
			pIdKey: "pId",
			rootPId: ""
		}
	},
	callback: {
		beforeClick: function(treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("tree");
			if (treeNode.isParent) {
				zTree.expandNode(treeNode);
				return false;
			} else {
				//demoIframe.attr("src",treeNode.file + ".html");
				return true;
			}
		}
	}
};

var zNodes =[
	{ id:1, pId:0, name:"一级分类", open:true},
	{ id:11, pId:1, name:"二级分类"},
	{ id:111, pId:11, name:"三级分类"},
	{ id:112, pId:11, name:"三级分类"},
	{ id:113, pId:11, name:"三级分类"},
	{ id:114, pId:11, name:"三级分类"},
	{ id:115, pId:11, name:"三级分类"},
	{ id:12, pId:1, name:"二级分类 1-2"},
	{ id:121, pId:12, name:"三级分类 1-2-1"},
	{ id:122, pId:12, name:"三级分类 1-2-2"},
];

function Detail_show(title,url,id,w,h){
    layer_show(title,url,w,h);
}
		
$(document).ready(function(){
	var t = $("#treeDemo");
	t = $.fn.zTree.init(t, setting, zNodes);
	//demoIframe = $("#testIframe");
	//demoIframe.on("load", loadReady);
	var zTree = $.fn.zTree.getZTreeObj("tree");
	//zTree.selectNode(zTree.getNodeByParam("id",'11'));
});

$('.table-sort').dataTable({
	"aaSorting": [[ 1, "desc" ]],//默认第几个排序
	"bStateSave": true,//状态保存
	"aoColumnDefs": [
	  {"orderable":false,"aTargets":[0,7]}// 制定列不参与排序
	]
});
/*产品-添加*/
function product_add(title,url){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}
/*产品-查看*/

function product_show(title,url,id){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}
/*产品-审核*/
function product_shenhe(obj,id){
	layer.confirm('审核文章？', {
		btn: ['通过','不通过'], 
		shade: false
	},
	function(){
		$(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="product_start(this,id)" href="javascript:;" title="申请上线">申请上线</a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已发布</span>');
		$(obj).remove();
		layer.msg('已发布', {icon:6,time:1000});
	},
	function(){
		$(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="product_shenqing(this,id)" href="javascript:;" title="申请上线">申请上线</a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-danger radius">未通过</span>');
		$(obj).remove();
    	layer.msg('未通过', {icon:5,time:1000});
	});	
}
/*未审核的改为审核的，true，数据库中改为0*/
function product_stop(obj,id){
	layer.confirm('确认要通过审核吗？',function(index){
        var garbageId = $(obj).parent().attr("garbageId");
        $.ajax({
            url:"<%=path%>/backstage/garbage/changeState",
            async:false,
            data:{flag:true,id:garbageId},
            type:"GET",
            success:function () {
            }
        })
		$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="product_start(this,id)" href="javascript:;" title="更改为未审核"><i class="Hui-iconfont">&#xe6de;</i></a>');
        $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已审核</span>');
		$(obj).remove();
		layer.msg('已通过审核!',{icon: 6,time:1000});
	});
}

/*将已审核的改为未审核的，false,数据库中改为1*/
function product_start(obj,id){
	layer.confirm('确认要更改为未审核状态吗？',function(index){
        var garbageId = $(obj).parent().attr("garbageId");
        $.ajax({
            url:"<%=path%>/backstage/garbage/changeState",
            async:false,
            data:{flag:false,id:garbageId},
            type:"GET",
            success:function () {
            }
        })
		$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="product_stop(this,id)" href="javascript:;" title="通过审核"><i class="Hui-iconfont">&#xe603;</i></a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">未审核</span>');
		$(obj).remove();
		layer.msg('已更改!',{icon: 5,time:1000});
	});
}

/*产品-申请上线*/
function product_shenqing(obj,id){
	$(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">待审核</span>');
	$(obj).parents("tr").find(".td-manage").html("");
	layer.msg('已提交申请，耐心等待审核!', {icon: 1,time:2000});
}

/*产品-编辑*/
function product_edit(title,url,id){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}

/*产品-删除*/
function product_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
        var garbageId = $(obj).parent().attr("garbageId");
		$.ajax({
			type: "get",
			url: "<%=path%>/backstage/garbage/deleteGarbage",
			data:{id:garbageId},
			success: function(data){
			    $(obj).parent().parent().remove();
				// $("#single [data-id="+garbageId+"]").remove();
				layer.msg('已删除!',{icon:1,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}
</script>
<%--</body>--%>
<%--</html>--%>